package com.zygh.policeasset.controller;

import com.github.pagehelper.PageInfo;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.BusinessProcessMain;
import com.zygh.policeasset.service.BusinessProcessMainService;
import com.zygh.policeasset.service.ProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/businessProcessMain"})
@Api(tags = {"业务流程主表"})
@RestController
public class BusinessProcessMainController {
    @Resource
    BusinessProcessMainService businessProcessMainService;
    @Resource
    ProjectService projectService;

    @GetMapping({"/queryById"})
    @ApiOperation("通过ID查询")
    public BusinessProcessMain queryById(Integer id) {
        return this.businessProcessMainService.queryById(id);
    }

    @GetMapping({"/queryAll"})
    @ApiOperation("获取项目分类列表")
    public PageInfo queryAll(@RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum,
                             @RequestParam(defaultValue = "10", value = "pageSize") Integer pageSize,
                             BusinessProcessMain businessProcessMain) {
        return this.businessProcessMainService.queryAll(pageNum.intValue(), pageSize.intValue(),
                businessProcessMain);
    }

    @PostMapping({"/insert"})
    @ApiOperation("添加")
    public CommonResult insert(@RequestBody BusinessProcessMain businessProcessMain) {
        return this.businessProcessMainService.insert(businessProcessMain);
    }

    @PostMapping({"/update"})
    @ApiOperation("修改")
    public CommonResult update(@RequestBody BusinessProcessMain businessProcessMain) {
        return this.businessProcessMainService.update(businessProcessMain);
    }

    @DeleteMapping({"/delete/{id}"})
    @ApiOperation("删除")
    public CommonResult delete(@PathVariable Integer id) {
        return this.businessProcessMainService.deleteById(id);
    }

    @ApiImplicitParams({@ApiImplicitParam(name = "projectNo", value = "项目编号", required = true, paramType = "query"),
            @ApiImplicitParam(name = "sectionId", value = "标段id", required = false, paramType = "query")})
    @GetMapping({"/findBusinessProcess"})
    @ApiOperation("项目资产各流程状态查询")
    public Object findBusinessProcess(@RequestParam("projectNo") String projectNo,
                                      @RequestParam(value = "sectionId", required = false) Integer sectionId) {
        return this.projectService.findBusinessProcess(projectNo, sectionId);
    }

    @ApiImplicitParams({@ApiImplicitParam(name = "projectNo", value = "项目编号", required = true, paramType = "query"), @ApiImplicitParam(name = "sectionId", value = "标段id，传空字符串", required = true, paramType = "query")})
    @GetMapping({"/findBusinessProcessPurchase"})
    @ApiOperation("采购资产各流程状态查询")
    public Object findBusinessProcessPurchase(@RequestParam("projectNo") String projectNo, @RequestParam("sectionId") Integer sectionId) {
        return this.projectService.findBusinessProcessPurchase(projectNo, sectionId);
    }

    @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "类型，传jc、zn、da、cg", required = true, paramType = "query"), @ApiImplicitParam(name = "name", value = "项目名称，模糊查询", required = false, paramType = "query")})
    @GetMapping({"/findProject"})
    @ApiOperation("项目查询")
    public Object findProject(@RequestParam("type") String type, @RequestParam(value = "name", required = false) String name) {
        return this.projectService.selectProject(type, name);
    }

    @ApiImplicitParams({@ApiImplicitParam(name = "projectNo", value = "jc、zn项目是此类型可传", required = true, paramType = "query")})
    @GetMapping({"/findSection"})
    @ApiOperation("项目标段查询")
    public Object findSection(@RequestParam("projectNo") String projectNo) {
        return this.projectService.findSection(projectNo);
    }
}